<!DOCTYPE html>
<html>
<head>
<title>安装MySQL.md</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">

<style>
/* https://github.com/microsoft/vscode/blob/master/extensions/markdown-language-features/media/markdown.css */
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

body {
	font-family: var(--vscode-markdown-font-family, -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif);
	font-size: var(--vscode-markdown-font-size, 14px);
	padding: 0 26px;
	line-height: var(--vscode-markdown-line-height, 22px);
	word-wrap: break-word;
}

#code-csp-warning {
	position: fixed;
	top: 0;
	right: 0;
	color: white;
	margin: 16px;
	text-align: center;
	font-size: 12px;
	font-family: sans-serif;
	background-color:#444444;
	cursor: pointer;
	padding: 6px;
	box-shadow: 1px 1px 1px rgba(0,0,0,.25);
}

#code-csp-warning:hover {
	text-decoration: none;
	background-color:#007acc;
	box-shadow: 2px 2px 2px rgba(0,0,0,.25);
}

body.scrollBeyondLastLine {
	margin-bottom: calc(100vh - 22px);
}

body.showEditorSelection .code-line {
	position: relative;
}

body.showEditorSelection .code-active-line:before,
body.showEditorSelection .code-line:hover:before {
	content: "";
	display: block;
	position: absolute;
	top: 0;
	left: -12px;
	height: 100%;
}

body.showEditorSelection li.code-active-line:before,
body.showEditorSelection li.code-line:hover:before {
	left: -30px;
}

.vscode-light.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(0, 0, 0, 0.15);
}

.vscode-light.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(0, 0, 0, 0.40);
}

.vscode-light.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

.vscode-dark.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(255, 255, 255, 0.4);
}

.vscode-dark.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(255, 255, 255, 0.60);
}

.vscode-dark.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

.vscode-high-contrast.showEditorSelection .code-active-line:before {
	border-left: 3px solid rgba(255, 160, 0, 0.7);
}

.vscode-high-contrast.showEditorSelection .code-line:hover:before {
	border-left: 3px solid rgba(255, 160, 0, 1);
}

.vscode-high-contrast.showEditorSelection .code-line .code-line:hover:before {
	border-left: none;
}

img {
	max-width: 100%;
	max-height: 100%;
}

a {
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

a:focus,
input:focus,
select:focus,
textarea:focus {
	outline: 1px solid -webkit-focus-ring-color;
	outline-offset: -1px;
}

hr {
	border: 0;
	height: 2px;
	border-bottom: 2px solid;
}

h1 {
	padding-bottom: 0.3em;
	line-height: 1.2;
	border-bottom-width: 1px;
	border-bottom-style: solid;
}

h1, h2, h3 {
	font-weight: normal;
}

table {
	border-collapse: collapse;
}

table > thead > tr > th {
	text-align: left;
	border-bottom: 1px solid;
}

table > thead > tr > th,
table > thead > tr > td,
table > tbody > tr > th,
table > tbody > tr > td {
	padding: 5px 10px;
}

table > tbody > tr + tr > td {
	border-top: 1px solid;
}

blockquote {
	margin: 0 7px 0 5px;
	padding: 0 16px 0 10px;
	border-left-width: 5px;
	border-left-style: solid;
}

code {
	font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
	font-size: 1em;
	line-height: 1.357em;
}

body.wordWrap pre {
	white-space: pre-wrap;
}

pre:not(.hljs),
pre.hljs code > div {
	padding: 16px;
	border-radius: 3px;
	overflow: auto;
}

pre code {
	color: var(--vscode-editor-foreground);
	tab-size: 4;
}

/** Theming */

.vscode-light pre {
	background-color: rgba(220, 220, 220, 0.4);
}

.vscode-dark pre {
	background-color: rgba(10, 10, 10, 0.4);
}

.vscode-high-contrast pre {
	background-color: rgb(0, 0, 0);
}

.vscode-high-contrast h1 {
	border-color: rgb(0, 0, 0);
}

.vscode-light table > thead > tr > th {
	border-color: rgba(0, 0, 0, 0.69);
}

.vscode-dark table > thead > tr > th {
	border-color: rgba(255, 255, 255, 0.69);
}

.vscode-light h1,
.vscode-light hr,
.vscode-light table > tbody > tr + tr > td {
	border-color: rgba(0, 0, 0, 0.18);
}

.vscode-dark h1,
.vscode-dark hr,
.vscode-dark table > tbody > tr + tr > td {
	border-color: rgba(255, 255, 255, 0.18);
}

</style>

<style>
/* Tomorrow Theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */

/* Tomorrow Comment */
.hljs-comment,
.hljs-quote {
	color: #8e908c;
}

/* Tomorrow Red */
.hljs-variable,
.hljs-template-variable,
.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-regexp,
.hljs-deletion {
	color: #c82829;
}

/* Tomorrow Orange */
.hljs-number,
.hljs-built_in,
.hljs-builtin-name,
.hljs-literal,
.hljs-type,
.hljs-params,
.hljs-meta,
.hljs-link {
	color: #f5871f;
}

/* Tomorrow Yellow */
.hljs-attribute {
	color: #eab700;
}

/* Tomorrow Green */
.hljs-string,
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
	color: #718c00;
}

/* Tomorrow Blue */
.hljs-title,
.hljs-section {
	color: #4271ae;
}

/* Tomorrow Purple */
.hljs-keyword,
.hljs-selector-tag {
	color: #8959a8;
}

.hljs {
	display: block;
	overflow-x: auto;
	color: #4d4d4c;
	padding: 0.5em;
}

.hljs-emphasis {
	font-style: italic;
}

.hljs-strong {
	font-weight: bold;
}
</style>

<style>
/*
 * Markdown PDF CSS
 */

 body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif, "Meiryo";
	padding: 0 12px;
}

pre {
	background-color: #f8f8f8;
	border: 1px solid #cccccc;
	border-radius: 3px;
	overflow-x: auto;
	white-space: pre-wrap;
	overflow-wrap: break-word;
}

pre:not(.hljs) {
	padding: 23px;
	line-height: 19px;
}

blockquote {
	background: rgba(127, 127, 127, 0.1);
	border-color: rgba(0, 122, 204, 0.5);
}

.emoji {
	height: 1.4em;
}

code {
	font-size: 14px;
	line-height: 19px;
}

/* for inline code */
:not(pre):not(.hljs) > code {
	color: #C9AE75; /* Change the old color so it seems less like an error */
	font-size: inherit;
}

/* Page Break : use <div class="page"/> to insert page break
-------------------------------------------------------- */
.page {
	page-break-after: always;
}

</style>

<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
</head>
<body>
  <script>
    mermaid.initialize({
      startOnLoad: true,
      theme: document.body.classList.contains('vscode-dark') || document.body.classList.contains('vscode-high-contrast')
          ? 'dark'
          : 'default'
    });
  </script>
<h3 id="%E7%AC%AC%E4%B8%80%E6%AD%A5%E5%88%87%E6%8D%A2%E9%95%9C%E5%83%8F%E6%BA%90%E8%83%BD%E7%94%A8%E5%88%99%E4%B8%8D%E9%9C%80%E8%A6%81%E6%9B%B4%E6%96%B0">第一步：切换镜像源(能用则不需要更新)</h3>
<h4 id="%E6%89%93%E5%BC%80etcyumreposd%E6%96%87%E4%BB%B6%E5%A4%B9%E5%88%A0%E9%99%A4%E6%89%80%E6%9C%89%E6%96%87%E4%BB%B6">打开/etc/yum.repos.d/文件夹删除所有文件</h4>
<pre class="hljs"><code><div>[root@localhost yum.repos.d]<span class="hljs-comment"># rm -rf C*</span>
</div></code></pre>
<h4 id="%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6%E5%B9%B6%E6%B7%BB%E5%8A%A0%E6%96%B0%E7%9A%84%E9%95%9C%E5%83%8F%E6%BA%90">新建文件并添加新的镜像源</h4>
<h5 id="%E6%96%B0%E5%BB%BA%E6%96%87%E4%BB%B6">新建文件</h5>
<pre class="hljs"><code><div>vi Centos7.repo
</div></code></pre>
<h5 id="%E6%89%BE%E5%88%B0%E4%B8%8B%E8%BD%BD%E9%95%9C%E5%83%8F%E6%BA%90%E5%B9%B6txt%E6%89%93%E5%BC%80">找到下载镜像源并txt打开</h5>
<p>https://mirrors.aliyun.com/repo/Centos-7.repo</p>
<h5 id="%E5%A4%8D%E5%88%B6%E4%BB%A3%E7%A0%81%E7%B2%98%E8%B4%B4%E5%88%B0%E6%96%B0%E5%BB%BA%E7%9A%84%E6%96%87%E4%BB%B6%E5%A4%B9">复制代码粘贴到新建的文件夹</h5>
<pre class="hljs"><code><div>[base]
name=CentOS-<span class="hljs-variable">$releasever</span> - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/<span class="hljs-variable">$releasever</span>/os/<span class="hljs-variable">$basearch</span>/
        http://mirrors.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/os/<span class="hljs-variable">$basearch</span>/
        http://mirrors.cloud.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/os/<span class="hljs-variable">$basearch</span>/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
<span class="hljs-comment">#released updates </span>
[updates]
name=CentOS-<span class="hljs-variable">$releasever</span> - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/<span class="hljs-variable">$releasever</span>/updates/<span class="hljs-variable">$basearch</span>/
        http://mirrors.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/updates/<span class="hljs-variable">$basearch</span>/
        http://mirrors.cloud.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/updates/<span class="hljs-variable">$basearch</span>/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
<span class="hljs-comment">#additional packages that may be useful</span>
[extras]
name=CentOS-<span class="hljs-variable">$releasever</span> - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/<span class="hljs-variable">$releasever</span>/extras/<span class="hljs-variable">$basearch</span>/
        http://mirrors.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/extras/<span class="hljs-variable">$basearch</span>/
        http://mirrors.cloud.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/extras/<span class="hljs-variable">$basearch</span>/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
<span class="hljs-comment">#additional packages that extend functionality of existing packages</span>
[centosplus]
name=CentOS-<span class="hljs-variable">$releasever</span> - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/<span class="hljs-variable">$releasever</span>/centosplus/<span class="hljs-variable">$basearch</span>/
        http://mirrors.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/centosplus/<span class="hljs-variable">$basearch</span>/
        http://mirrors.cloud.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/centosplus/<span class="hljs-variable">$basearch</span>/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
<span class="hljs-comment">#contrib - packages by Centos Users</span>
[contrib]
name=CentOS-<span class="hljs-variable">$releasever</span> - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/<span class="hljs-variable">$releasever</span>/contrib/<span class="hljs-variable">$basearch</span>/
        http://mirrors.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/contrib/<span class="hljs-variable">$basearch</span>/
        http://mirrors.cloud.aliyuncs.com/centos/<span class="hljs-variable">$releasever</span>/contrib/<span class="hljs-variable">$basearch</span>/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
</div></code></pre>
<h4 id="%E6%B8%85%E7%90%86%E7%BC%93%E5%AD%98%E5%B9%B6%E4%BB%8E%E6%96%B0%E7%94%9F%E6%88%90%E7%BC%93%E5%AD%98">清理缓存并从新生成缓存</h4>
<pre class="hljs"><code><div><span class="hljs-comment"># 清理缓存</span>
[root@localhost yum.repos.d]<span class="hljs-comment"># yum clean all</span>
<span class="hljs-comment"># 重新加载缓存</span>
[root@localhost yum.repos.d]<span class="hljs-comment"># yum makecache</span>
</div></code></pre>
<h3 id="%E7%AC%AC%E4%BA%8C%E6%AD%A5%E5%AE%89%E8%A3%85docker">第二步：安装docker</h3>
<h4 id="%E6%9F%A5%E7%9C%8B%E5%86%85%E6%A0%B8%E7%89%88%E6%9C%AC">查看内核版本</h4>
<pre class="hljs"><code><div>[root@localhost ~]<span class="hljs-comment"># uname -r</span>
</div></code></pre>
<h4 id="root%E6%9D%83%E9%99%90%E6%9B%B4%E6%96%B0yum%E5%8C%85">root权限更新Yum包</h4>
<pre class="hljs"><code><div><span class="hljs-comment"># 注意：中途输入y即可</span>
[root@localhost ~]<span class="hljs-comment"># yum update</span>
</div></code></pre>
<h4 id="%E8%AE%BE%E7%BD%AEyum%E6%BA%90">设置Yum源</h4>
<pre class="hljs"><code><div>[root@localhost ~]<span class="hljs-comment">#  yum install -y yum-utils device-mapper-persistent-data lvm2</span>
</div></code></pre>
<h4 id="%E6%B7%BB%E5%8A%A0docker%E7%9A%84yum%E6%BA%90">添加docker的yum源</h4>
<pre class="hljs"><code><div>[root@localhost ~]<span class="hljs-comment"># yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo</span>
</div></code></pre>
<h4 id="%E6%9F%A5%E7%9C%8B%E4%BB%93%E5%BA%93%E4%B8%AD%E6%89%80%E6%9C%89%E7%9A%84docker%E7%89%88%E6%9C%AC">查看仓库中所有的docker版本</h4>
<pre class="hljs"><code><div>[root@localhost ~]<span class="hljs-comment"># yum list docker-ce --showduplicates | sort -r</span>
</div></code></pre>
<h4 id="%E9%85%8D%E7%BD%AE%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F%E5%99%A8">配置镜像加速器</h4>
<h5 id="%E6%9B%B4%E6%94%B9etcdockerdaemonjson%E9%87%8C%E7%9A%84%E5%86%85%E5%AE%B9-%E6%B2%A1%E6%9C%89%E5%88%99%E6%96%B0%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%AD%A4%E5%A4%84%E4%BD%BF%E7%94%A8%E7%9A%84%E6%98%AF%E9%98%BF%E9%87%8C%E4%BA%91%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F">更改/etc/docker/daemon.json里的内容 没有则新建一个(此处使用的是阿里云镜像加速)</h5>
<pre class="hljs"><code><div><span class="hljs-comment"># 新建docker目录</span>
[root@localhost etc]<span class="hljs-comment"># mkdir docker</span>
<span class="hljs-comment"># 新建daemon.json</span>
[root@localhost etc]<span class="hljs-comment"># vi /etc/docker/daemon.json</span>
<span class="hljs-comment"># 输入以下内容</span>
{
  <span class="hljs-string">"registry-mirrors"</span>: [<span class="hljs-string">"https://docker.mirrors.ustc.edu.cn"</span>]
}
</div></code></pre>
<h4 id="%E5%AE%89%E8%A3%85docker">安装docker</h4>
<pre class="hljs"><code><div><span class="hljs-comment"># 查找所有版本 安装自己想要的版本</span>
[root@localhost ~]<span class="hljs-comment"># yum install docker-ce.x86_64</span>
<span class="hljs-comment"># 启动docker</span>
[root@localhost ~]<span class="hljs-comment"># systemctl start docker</span>
<span class="hljs-comment"># 开机自启动(也可以不设置)</span>
[root@localhost ~]<span class="hljs-comment"># systemctl enable docker</span>
<span class="hljs-comment"># 查看版本号</span>
[root@localhost ~]<span class="hljs-comment"># docker version</span>
<span class="hljs-comment"># 验证是否安装成功</span>
 docker run hello-world

</div></code></pre>
<h3 id="%E5%AE%89%E8%A3%85mysql">安装MySQL</h3>
<h4 id="%E6%8B%89%E5%8F%96mysql%E7%9A%84%E9%95%9C%E5%83%8F-%E9%BB%98%E8%AE%A4%E6%9C%80%E6%96%B0%E7%89%88">拉取MySQL的镜像 默认最新版</h4>
<pre class="hljs"><code><div>[root@localhost ~]<span class="hljs-comment"># docker pull mysql</span>
</div></code></pre>
<h4 id="%E6%9F%A5%E7%9C%8B%E9%95%9C%E5%83%8F">查看镜像</h4>
<pre class="hljs"><code><div>[root@localhost ~]<span class="hljs-comment"># docker images</span>
</div></code></pre>
<h4 id="%E5%90%AF%E5%8A%A8-%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AAmysql%E7%9A%84%E5%AE%B9%E5%99%A8%E5%B9%B6%E8%BF%90%E8%A1%8C-%E5%90%8D%E5%AD%97%E4%B8%BAmysql%E5%8F%AF%E4%BB%A5%E9%9A%8F%E4%BE%BF%E5%8F%96">启动 创建一个MySQL的容器并运行 名字为mysql(可以随便取)</h4>
<pre class="hljs"><code><div>docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql
</div></code></pre>
<h4 id="docker%E6%9F%A5%E7%9C%8B%E5%AE%B9%E5%99%A8">docker查看容器</h4>
<pre class="hljs"><code><div>[root@localhost ~]<span class="hljs-comment"># docker ps -a</span>
</div></code></pre>
<h4 id="%E8%BF%9B%E5%85%A5%E5%AE%B9%E5%99%A8%E5%B9%B6%E8%BF%9B%E5%85%A5mysql%E8%AE%BE%E7%BD%AE%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AE">进入容器并进入MySQL设置远程访问</h4>
<pre class="hljs"><code><div><span class="hljs-comment"># 进入容器</span>
[root@localhost ~]<span class="hljs-comment"># docker exec -it mysql bash</span>
<span class="hljs-comment"># 进入MySQL</span>
root@e656edbb98ea:/<span class="hljs-comment"># mysql -u root -proot</span>
<span class="hljs-comment"># 设置远程访问 注意：远程连接时需要关闭防火墙</span>
 ALTER USER <span class="hljs-string">'root'</span>@<span class="hljs-string">'%'</span> IDENTIFIED WITH mysql_native_password BY <span class="hljs-string">'root'</span>;
<span class="hljs-comment"># 刷新权限</span>
mysql&gt; FLUSH PRIVILEGES;
</div></code></pre>

</body>
</html>
